import sys,os
from collections import defaultdict,Counter
from math import ceil,gcd,sqrt
from bisect import bisect_left
f=False
INT_MAX=sys.maxsize
if os.getcwd()=="/Users/mehtaparityatinbhai/Desktop/test_codes":
sys.stdin = open('inp.txt', 'r')
sys.stdout = open('out.txt', 'w')
f=True
def lcm(a,b):
return (a*b)//gcd(a,b)
def readint():
return int(input())
def readlst():
return list(map(int, input().split()))
def leftrotate(a,l,r):
return a[l+1:r]+a[:l+1]+a[r:]
def is_prime(n):
if n < 5 or n & 1 == 0 or n % 3 == 0:
return 2 <= n <= 3
s = ((n - 1) & (1 - n)).bit_length() - 1
d = n >> s
for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
p = pow(a, d, n)
if p == 1 or p == n - 1 or a % n == 0:
continue
for _ in range(s):
p = (p * p) % n
if p == n - 1:
break
else:
return False
return True
def sol(cnt):
n=readint()
s=input()
res=''
for i in range(n):
if len(res)&1==0:
res+=s[i]
else:
if res[-1]==s[i]:
continue
else:
res=res+s[i]
if len(res)&1:
res=res[:-1]
print(len(s)-len(res))
print(res)
return
def main():
tc=1
cnt=0
for _ in range(tc):
cnt+=1
sol(cnt)
main()
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define endl "\n"
#define pb push_back
#define popb pop_back
#define mod 1000000007
# define f first
#define s second
int main()
{
ll t=1;
fast;
//cin>>t;
while(t--)
{
ll n;
cin>>n;
string s;
cin>>s;
stack<char>ss;
ss.push(s[0]);
for (ll i=1;i<n;i++)
{
if(ss.top()!=s[i])
ss.push(s[i]);
else
{
if (ss.size()%2==0)
ss.push(s[i]);
}
}
while(ss.size()%2)
ss.pop();
string ans="";
while(!ss.empty())
{
ans+=ss.top();
ss.pop();
}
reverse(ans.begin(),ans.end());
cout<<n-ans.size()<<endl;
cout<<ans<<endl;
}
}
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |
445. Add Two Numbers II | 442. Find All Duplicates in an Array |
437. Path Sum III | 436. Find Right Interval |
435. Non-overlapping Intervals | 406. Queue Reconstruction by Height |
380. Insert Delete GetRandom O(1) | 332. Reconstruct Itinerary |
368. Largest Divisible Subset | 377. Combination Sum IV |
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |
260. Single Number III | 240. Search a 2D Matrix II |
238. Product of Array Except Self | 229. Majority Element II |
222. Count Complete Tree Nodes | 215. Kth Largest Element in an Array |
198. House Robber | 153. Find Minimum in Rotated Sorted Array |
150. Evaluate Reverse Polish Notation | 144. Binary Tree Preorder Traversal |